package com.scau.dao.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.scau.dao.LoginDataDao;
import com.scau.mapper.LogindataMapper;
import com.scau.pojo.Logindata;
import com.scau.util.SqlSessionFactoryUtil;
@Repository
public class LoginDataDaoImpl implements LoginDataDao{
	
	SqlSession session = SqlSessionFactoryUtil.getSession();
	LogindataMapper loginDataMapper=session.getMapper(LogindataMapper.class);
	
	@Override
	public List<Logindata> query() {
		return loginDataMapper.selectByExample(null);
	}

	@Override
	public Map<String, Object> getUserByName(String username) {
		 Map<String, Object> map=new HashMap<String,Object>();
		try {
			Logindata loginuser=loginDataMapper.selectByName(username);
			if(loginuser!=null){
				map.put("returnCode", 1);
				map.put("logindata", loginuser);
			}else{
				map.put("returnCode", -1);
				map.put("logindata",null);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	@Override
	public int insert(Logindata logindata) {
		return loginDataMapper.insert(logindata);
	}

	@Override
	public int update(Logindata logindata) {
		return loginDataMapper.updateByPrimaryKeySelective(logindata);
	}
}
